package com.alibaba.citrus.cr.unified.inventory.facade.service;

import com.alibaba.citrus.cr.common.exception.FacadeException;
import com.alibaba.citrus.cr.common.util.QuantityFormatUtils;
import com.alibaba.citrus.cr.common.util.SapAndCrmFieldDealUtils;
import com.alibaba.cz.base.tool.log.Log;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.lattice2.epoch.sdk.model.Result;
import com.epoch.app.bcorder.model.dto.*;
import com.epoch.app.bcorder.service.BaseDataService;
import com.epoch.app.bcorder.service.UnifiedInventoryService;
import com.epoch.app.crunifiedinventory.domain.allocateorder.dto.AllocateOrderLoadListRequest;
import com.epoch.app.crunifiedinventory.domain.allocateorder.model.AllocateOrder;
import com.epoch.app.crunifiedinventory.domain.allocateorder.service.AllocateOrderService;
import com.epoch.app.crunifiedinventory.domain.allocateorderdetail.dto.AllocateOrderDetailLoadListRequest;
import com.epoch.app.crunifiedinventory.domain.allocateorderdetail.model.AllocateOrderDetail;
import com.epoch.app.crunifiedinventory.domain.allocateorderdetail.service.AllocateOrderDetailService;
import com.epoch.app.crunifiedinventory.inventorychecker.dto.*;
import com.epoch.app.crunifiedinventory.inventorychecker.model.InventoryChecker;
import com.epoch.app.crunifiedinventory.inventorychecker.service.InventoryCheckerService;
import com.epoch.app.crunifiedinventory.model.dto.*;
import com.epoch.app.crunifiedinventory.sdo.enums.InventoryCheckStatus;
import com.epoch.app.crunifiedinventory.service.CrUnifiedInventoryService;
import com.google.common.collect.Lists;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @author Chen.mu
 * @date 2022/1/17
 */
@Service
@Primary
public class InventoryCheckerServiceImpl implements InventoryCheckerService {
    private static Log log = Log.getLogger(InventoryCheckerServiceImpl.class);
    @Autowired
    private CrUnifiedInventoryService otsUnifiedInventoryService;
    @Resource
    private BaseDataService baseDataService;
    @Autowired
    private UnifiedInventoryService unifiedInventoryService;
    @Autowired
    private AllocateOrderService allocateOrderService;
    @Autowired
    private AllocateOrderDetailService allocateOrderDetailService;

    /**
     * 批次维度 的 校验总库存
     *
     * @param request
     * @return
     */
    @Override
    public Result<List<InventoryCheckerRequest>> importInventoryData2Check(ImportInventoryData2CheckRequest request) {
        Set<String> goodsId = new HashSet<>();
        Set<String> warehouseCodes = new HashSet<>();
        List<InventoryCheckerRequest> reslutList = request.getInventoryData();
        //bivc:business inventory check
        if (CollectionUtils.isNotEmpty(reslutList)) {
            reslutList.stream().forEach(x -> {
                        x.setGoodsCode(SapAndCrmFieldDealUtils.subStringScItmCode(x.getGoodsCode()));
                        if (StringUtils.isEmpty(x.getGoodsCode())
                                && StringUtils.isEmpty(x.getWarehouseCode())
                                && StringUtils.isEmpty(x.getFatoryCode())) {
                            //3个code都是空的 可能是最后一行 汇总行。 跳过
                            return;
                        }
                        if (StringUtils.isEmpty(x.getGoodsCode())
                                || StringUtils.isEmpty(x.getWarehouseCode())
                                || StringUtils.isEmpty(x.getFatoryCode())) {
                            x.setErrorMessage("excel数据有误，请检查工厂及仓库code 和物料编码不能为空");
                        } else {
                            goodsId.add(x.getGoodsCode());
                            warehouseCodes.add(x.getWarehouseCode());
                        }
                    }
            );
        }
        Map<String, ScItemSDO> goods = getGoodsListWithOuterId(goodsId);
        Map<String, WarehouseInfo> warehouses = getWarehouseList(warehouseCodes, true);
        List<InventoryCheckerRequest> inventoryCheckerList = new ArrayList<>();
        reslutList.stream().forEach(x -> {
            if (StringUtils.isEmpty(x.getGoodsCode())
                    && StringUtils.isEmpty(x.getWarehouseCode())
                    && StringUtils.isEmpty(x.getFatoryCode())) {
                //3个code都是空的 可能是最后一行 汇总行。 跳过
                return;
            }
            InventoryChecker inventoryChecker = new InventoryChecker();
            WarehouseInfo warehouseInfo = warehouses.get(x.getFatoryCode() + "_" + x.getWarehouseCode());
            inventoryChecker.setWarehouseCode(x.getWarehouseCode());
            inventoryChecker.setFactoryCode(x.getFatoryCode());
            inventoryChecker.setGoodsCode(x.getGoodsCode());
            inventoryChecker.setExcelName(x.getExcelName());
            InventoryCheckStatus failStatus = InventoryCheckStatus.OK;
            //货品code 仓库code不能为空
            if (warehouseInfo == null) {
                failStatus = InventoryCheckStatus.WAREHOUSE_FAIL;
            }
            if (goods.get(x.getGoodsCode()) == null) {
                failStatus = InventoryCheckStatus.GOODS_FAIL;
            }
            // BigDecimal availabelQuantity = new BigDecimal(0);
            BigDecimal totalQuantity = new BigDecimal(0);
            try {
                totalQuantity = QuantityFormatUtils.formatQuantityForDB(x.getTotalQuantity());
            } catch (Exception e) {
                failStatus = InventoryCheckStatus.QUANTITY_FORMAT_FAIL;
            }
            long totalGap = 0;
            InventoryQueryResultForCheck inventoryCheck = null;
            if (failStatus.getValue() > 0) {
                inventoryCheck = getBizInventory(goods.get(x.getGoodsCode()).getScItemId(), warehouseInfo.getId(), x.getBatchNo(), 2);
                if (inventoryCheck == null) {
                    failStatus = InventoryCheckStatus.INVENTORY_FAIL;
                }
                if (inventoryCheck != null) {
                    totalGap = totalQuantity.longValue() - inventoryCheck.getTotalQuantity();
                }
                if (totalGap != 0) {
                    failStatus = InventoryCheckStatus.INV_QUANTITY_FAIL;
                }
                if (failStatus.getValue() < 0) {
                    inventoryCheckerList.add(x);
                }
            }
            inventoryChecker.setBatchNo(x.getBatchNo());
            inventoryChecker.setOutTotalQuantity(QuantityFormatUtils.formatQuantityForDB(x.getTotalQuantity()).longValue());
            inventoryChecker.setTotalQuantityGap(totalGap);
            if (inventoryCheck != null) {
                inventoryChecker.setInventoryId(inventoryCheck.getId());
                inventoryChecker.setInTotalQuantity(inventoryCheck.getTotalQuantity());
            }
            if (warehouseInfo != null) {
                inventoryChecker.setWarehouseAreaId(warehouseInfo.getId());
                inventoryChecker.setWarehouseId(warehouseInfo.getWarehouseId());
            } else {
                inventoryChecker.setWarehouseAreaId("-1");
                inventoryChecker.setWarehouseId("-1");
            }
            if (goods.get(x.getGoodsCode()) != null) {
                inventoryChecker.setGoodsId(goods.get(x.getGoodsCode()).getScItemId());
            } else {
                inventoryChecker.setGoodsId("-1");
            }
            inventoryChecker.setExcelId("BIVC" + x.getExcelId());
            inventoryChecker.setCheckStatus(failStatus.getValue());
            inventoryChecker.setCheckMsg(failStatus.getLabel());
            inventoryChecker.setType(1);
            create(inventoryChecker);
        });
        return Result.success(reslutList);
    }

    /**
     * 获取货品 通过外部id
     *
     * @param goodsCode
     * @return
     */
    private Map<String, ScItemSDO> getGoodsListWithOuterId(Set<String> goodsCode) {
        SearchScItemRequest searchScItemRequest = new SearchScItemRequest();
        Map<String, List<String>> outerIdList = new HashMap<>();
        outerIdList.put("outerIdList", goodsCode.stream().collect(Collectors.toList()));
        outerIdList.put("statusList", Arrays.asList("1", "-1"));
        searchScItemRequest.setPageSize(goodsCode.size());
        searchScItemRequest.setSearchReqDTO(outerIdList);
        Result<List<ScItemSDO>> scItemResult = baseDataService.searchScItem(searchScItemRequest);
        if (scItemResult == null) {
            throw new FacadeException("OTS-03-001-01-15-002", JSON.toJSONString(goodsCode));
        }
        if (org.apache.commons.collections4.CollectionUtils.isEmpty(scItemResult.getResult())) {
            throw new FacadeException("OTS-03-001-01-15-015", JSON.toJSONString(goodsCode));
        }
        Map<String, ScItemSDO> scItems = scItemResult.getResult().stream().collect(Collectors.toMap(x -> x.getOuterId(), x -> x, (v1, v2) -> v2));
        return scItems;
    }

    /**
     * 获取货品 通过内部id
     *
     * @param goodsCode
     * @return
     */
    private Map<String, ScItemSDO> getGoodsList(Set<String> goodsCode) {
        SearchScItemRequest searchScItemRequest = new SearchScItemRequest();
        Map<String, List<String>> outerIdList = new HashMap<>();
        outerIdList.put("scItemIds", goodsCode.stream().collect(Collectors.toList()));
        outerIdList.put("statusList", Arrays.asList("1", "-1"));
        searchScItemRequest.setPageSize(goodsCode.size());
        searchScItemRequest.setSearchReqDTO(outerIdList);
        Result<List<ScItemSDO>> scItemResult = baseDataService.searchScItem(searchScItemRequest);
        if (scItemResult == null) {
            return new HashMap<>();
        }
        if (org.apache.commons.collections4.CollectionUtils.isEmpty(scItemResult.getResult())) {
            return new HashMap<>();
        }
        Map<String, ScItemSDO> scItems = scItemResult.getResult().stream().collect(Collectors.toMap(x -> x.getScItemId(), x -> x, (v1, v2) -> v2));
        return scItems;
    }

    /**
     * 获取仓库
     */
    private Map<String, WarehouseInfo> getWarehouseList(Set<String> warehouseCodes, boolean useCodeAskey) {
        Map<String, WarehouseInfo> resultMap = new HashMap<>();
        List<String> warehouseCodeList = new ArrayList(warehouseCodes);
        List<List<String>> codesPartition = Lists.partition(warehouseCodeList, 10);
        for (List<String> tmp : codesPartition) {
            SearchCargoZoneListRequest request = new SearchCargoZoneListRequest();
            if (useCodeAskey) {
                request.setWarehouseCodes(new ArrayList(tmp));
            } else {
                request.setWarehouseAreaIds(new ArrayList(tmp));
            }
            //通一逻辑仓code 可能对应多个工厂code，为了保险，10个逻辑仓code查 就匹配100条数据足够了
            request.setLimit(100);
            SearchCargoZoneListResponse resp = unifiedInventoryService.searchCargoZoneList(request);
            if (resp.getResult() != null) {
                if (useCodeAskey) {
                    resp.getResult().stream().forEach(x -> {
                        resultMap.put(x.getSapFactoryCode() + "_" + x.getWarehouseCode(), x);
                    });
                } else {
                    resp.getResult().stream().forEach(x -> {
                        resultMap.put(x.getId(), x);
                    });
                }
            }
        }
        return resultMap;
    }

    /**
     * 获取库存
     *
     * @param goodsId
     * @param warehouseAreaId
     * @param batchNo
     * @param type            2批次  1仓库库存
     * @return
     */
    private InventoryQueryResultForCheck getBizInventory(String goodsId, String warehouseAreaId, String batchNo, int type) {
        GetListBatchStockForCheckRequest inventoryRequest = new GetListBatchStockForCheckRequest();
        inventoryRequest.setGoodsId(goodsId);
        inventoryRequest.setWarehouseAreaId(warehouseAreaId);
        inventoryRequest.setBatchNo(batchNo);
        inventoryRequest.setType(type);
        GetListBatchStockForCheckResponse resp = otsUnifiedInventoryService.getListBatchStockForCheck(inventoryRequest);
        if (CollectionUtils.isNotEmpty(resp.getResult())) {
            return resp.getResult().get(0);
        }
        return null;
    }

    @Override
    public Result<List<InventoryCheckDetailResult>> getCheckResult(GetCheckResultRequest getCheckResultRequest) {
        GetTargetEexcelResultRequest request = new GetTargetEexcelResultRequest();
        GetTargetEexcelTotalRequest totaoRequest = new GetTargetEexcelTotalRequest();
        BeanUtils.copyProperties(getCheckResultRequest, request);
        BeanUtils.copyProperties(getCheckResultRequest, totaoRequest);
        GetTargetEexcelResultResponse response = getTargetEexcelResult(request);
        Result<List<PageTotalResponse>> pageResponse = getTargetEexcelTotal(totaoRequest);
        if (CollectionUtils.isEmpty(response.getResult())) {
            return Result.listEmptySuccess();
        }
        List<InventoryCheckDetailResult> resp = new ArrayList<>();
        Set<String> goodsIds = new HashSet<>();
        Set<String> warehouseAreaIds = new HashSet<>();
        Set<String> warehouseIds = new HashSet<>();
        response.getResult().stream().forEach(x -> {
            InventoryCheckDetailResult result = new InventoryCheckDetailResult();
            if (StringUtils.isNotBlank(x.getGoodsId()) && !"-1".equals(x.getGoodsId())) {
                goodsIds.add(x.getGoodsId());
            }
            if (StringUtils.isNotBlank(x.getWarehouseAreaId()) && !"-1".equals(x.getWarehouseAreaId())) {
                warehouseAreaIds.add(x.getWarehouseAreaId());
                warehouseIds.add(x.getWarehouseId());
            }
            BeanUtils.copyProperties(x, result);
            result.setInAvailabelQuantityFormat(formartQuantity(x.getInAvailabelQuantity()));
            result.setInTotalQuantityFormat(formartQuantity(x.getInTotalQuantity()));
            result.setOutAvailabelQuantityFormat(formartQuantity(x.getOutAvailabelQuantity()));
            result.setOutTotalQuantityFormat(formartQuantity(x.getOutTotalQuantity()));
            result.setAvailabelQuantityGapFormat(formartQuantity(x.getAvailabelQuantityGap()));
            result.setTotalQuantityGapFormat(formartQuantity(x.getTotalQuantityGap()));
            result.setErrorMessage(x.getCheckMsg());
            result.setOutWithholdingQuantityFormat(formartQuantity(x.getOutWithholdingQuantity()));
            result.setInWithholdingQuantityFormat(formartQuantity(x.getInWithholdingQuantity()));
            resp.add(result);
        });
        Map<String, ScItemSDO> goods = getGoodsList(goodsIds);
        Map<String, WarehouseInfo> warehouseAreas = getWarehouseList(warehouseAreaIds, false);
        Map<String, WarehouseInfo> warehouses = getWarehouseList(warehouseIds, false);
        resp.stream().forEach(x -> {
            x.setGoodsCode(x.getGoodsId());
            x.setGoodsName(x.getGoodsId());
            ScItemSDO goodsInfo = goods.get(x.getGoodsId());
            if (goodsInfo != null) {
                x.setGoodsCode(goodsInfo.getOuterId());
                x.setGoodsName(goodsInfo.getTitle());
            }
            x.setWarehouseName("-");
            x.setWarehouseAreaName("-");
            if (warehouses.get(x.getWarehouseId()) != null) {
                x.setWarehouseName(warehouses.get(x.getWarehouseId()).getName());
            }
            if (warehouseAreas.get(x.getWarehouseAreaId()) != null) {
                x.setWarehouseAreaName(warehouseAreas.get(x.getWarehouseAreaId()).getName());
            }
        });
        return Result.listSuccess(resp, pageResponse.getResult().get(0).getTotal());
    }

    private String formartQuantity(Long quantity) {
        if (quantity == null) {
            return "-";
        }
        return QuantityFormatUtils.getQuantityForPage(quantity.toString()).toString();
    }

    /**
     * 计划调拨单对账
     *
     * @param importAndCompareRequest
     * @return
     */
    public ImportAndCompareResponse importAndCompare(ImportAndCompareRequest importAndCompareRequest) {
        List<String> errorList = new ArrayList<>();
        int successCount = 0;

        if (CollectionUtils.isEmpty(importAndCompareRequest.getImportData())) {
            return new ImportAndCompareResponse();
        }

        for (ImportInventoryCompareRequest request : importAndCompareRequest.getImportData()) {
            AllocateOrderDetail detail = getAllocateOrderDetailByOutAllocateIdAndItemId(request.getOrderNo(), request.getScItemOutId());
            if (Objects.isNull(detail)) {
                errorList.add(request.getOrderNo());
                continue;
            }
            //对比项：销售订单数量\确认数量\到货数量\交货单数量\出库数量
            if (detail.getQuantity().equalsIgnoreCase(request.getSaleOrderQuantity()) &&
                    detail.getConfirmQuantity().equalsIgnoreCase(request.getComfirmQuantity()) &&
                    detail.getDeliveryQuantity().equals(request.getDeliveryQuantity()) &&
                    detail.getReceiveQuantity().toString().equals(request.getReceivedQuantity()) &&
                    detail.getShipQuantity().toString().equals(request.getOutQuantity())) {
                successCount++;
                continue;
            }
            errorList.add(request.getOrderNo());
        }

        ImportAndCompareResponse response = new ImportAndCompareResponse();
        response.setResult(errorList);
        response.setSuccessCount(successCount);
        response.setSuccess(errorList.isEmpty()?Boolean.TRUE: Boolean.FALSE);
        response.setFailureCount(errorList.size());
        log.info("importAndCompare result:{}", JSONObject.toJSONString(response));
        return response;
    }

    /**
     * 根据计划调拨单外部单号和货品外部单号获取计划调拨单明细
     *
     * @param outAllocateId
     * @param outItemId
     * @return
     */
    private AllocateOrderDetail getAllocateOrderDetailByOutAllocateIdAndItemId(String outAllocateId, String outItemId) {
        AllocateOrderDetailLoadListRequest allocateOrderDetailRequest = new AllocateOrderDetailLoadListRequest();
        AllocateOrderLoadListRequest allocateOrderLoadListRequest = new AllocateOrderLoadListRequest();
        allocateOrderLoadListRequest.setOutAllocateOrderId(outAllocateId);
        Result<List<AllocateOrder>> orderResult = allocateOrderService.loadAllocateOrderList(allocateOrderLoadListRequest);
        if (CollectionUtils.isEmpty(orderResult.getResult())) {
            return null;
        }
        allocateOrderDetailRequest.setAllocateOrderId(orderResult.getResult().get(0).getId());
        Result<List<AllocateOrderDetail>> result = allocateOrderDetailService.loadAllocateOrderDetailList(allocateOrderDetailRequest);
        if (CollectionUtils.isEmpty(result.getResult())) {
            return null;
        }
        for (AllocateOrderDetail detail : result.getResult()) {
            if (outItemId.equals(detail.getScItemCode())) {
                return detail;
            }
        }

        return null;
    }

    /**
     * 批次维度 的 校验可用库存
     *
     * @param request
     * @return
     */
    @Override
    public Result<InventoryCheckResult> importGoodsInventoryData2Check(ImportGoodsInventoryData2CheckRequest request) {
        Set<String> goodsId = new HashSet<>();
        Set<String> warehouseCodes = new HashSet<>();
        //bivc:business inventory check
        if (CollectionUtils.isNotEmpty(request.getInventoryData())) {
            request.getInventoryData().stream().forEach(x -> {
                        x.setGoodsCode(SapAndCrmFieldDealUtils.subStringScItmCode(x.getGoodsCode()));
                        if (StringUtils.isEmpty(x.getGoodsCode())
                                || StringUtils.isEmpty(x.getWarehouseCode())
                                || StringUtils.isEmpty(x.getFatoryCode())) {
                            x.setErrorMessage("excel数据有误，请检查工厂及仓库code 和物料编码不能为空");
                        } else {
                            goodsId.add(x.getGoodsCode());
                            warehouseCodes.add(x.getWarehouseCode());
                        }
                    }
            );
        }
        Map<String, ScItemSDO> goods = getGoodsListWithOuterId(goodsId);
        Map<String, WarehouseInfo> warehouses = getWarehouseList(warehouseCodes, true);
        List<InventoryCheckerRequest> inventoryCheckerList = new ArrayList<>();
        request.getInventoryData().stream().forEach(x -> {
            InventoryChecker inventoryChecker = new InventoryChecker();
            WarehouseInfo warehouseInfo = warehouses.get(x.getFatoryCode() + "_" + x.getWarehouseCode());
            inventoryChecker.setWarehouseCode(x.getWarehouseCode());
            inventoryChecker.setFactoryCode(x.getFatoryCode());
            inventoryChecker.setGoodsCode(x.getGoodsCode());
            inventoryChecker.setExcelName(x.getExcelName());
            InventoryCheckStatus failStatus = InventoryCheckStatus.OK;
            //货品code 仓库code不能为空
            if (warehouseInfo == null) {
                failStatus = InventoryCheckStatus.WAREHOUSE_FAIL;
            }
            if (goods.get(x.getGoodsCode()) == null) {
                failStatus = InventoryCheckStatus.GOODS_FAIL;
            }
            BigDecimal availabelQuantity = new BigDecimal(0);
            BigDecimal saleWithholdingQuantity = new BigDecimal(0);
            try {
                availabelQuantity = QuantityFormatUtils.formatQuantityForDB(x.getAvailabelQuantity());
                saleWithholdingQuantity = QuantityFormatUtils.formatQuantityForDB(x.getSaleWithHoldQuantity());
            } catch (Exception e) {
                failStatus = InventoryCheckStatus.QUANTITY_FORMAT_FAIL;
            }
            long availabelGap = 0;
            InventoryQueryResultForCheck inventoryCheck = null;
            if (failStatus.getValue() > 0) {
                inventoryCheck = getBizInventory(goods.get(x.getGoodsCode()).getScItemId(), warehouseInfo.getId(), null, 1);
                if (inventoryCheck == null) {
                    failStatus = InventoryCheckStatus.INVENTORY_FAIL;
                }
                if (inventoryCheck != null) {
                    //共享仓 没有销售预占 有调拨单预占， 进行库存比较时 拿我们的额总库存与SAP可用进行比较 不用可用库存直接比
                    //
                    //0317调整为不关什么仓库 都是sap的（可用+预占)-(平台的可用+预占)
                    availabelGap = availabelQuantity.longValue() +
                            saleWithholdingQuantity.longValue() -
                            inventoryCheck.getAvailableQuantity() - inventoryCheck.getWithholdingQuantity();
                    //0317前
//                    if (warehouseInfo != null && warehouseInfo.getType() == 2) {
//                        availabelGap = availabelQuantity.longValue()+
//                                saleWithholdingQuantity.longValue() -
//                                inventoryCheck.getTotalQuantity()-inventoryCheck.getWithholdingQuantity();
//                    } else {
//                        availabelGap = availabelQuantity.longValue()-inventoryCheck.getAvailableQuantity();
//                    }
                }

                if (availabelGap != 0) {
                    failStatus = InventoryCheckStatus.INV_QUANTITY_FAIL;
                }
                if (failStatus.getValue() < 0) {
                    inventoryCheckerList.add(x);
                }
            }
            inventoryChecker.setBatchNo(x.getBatchNo());
            inventoryChecker.setOutAvailabelQuantity(QuantityFormatUtils.formatQuantityForDB(x.getAvailabelQuantity()).longValue());
            inventoryChecker.setAvailabelQuantityGap(availabelGap);
            inventoryChecker.setOutWithholdingQuantity(QuantityFormatUtils.formatQuantityForDB(x.getSaleWithHoldQuantity()).longValue());

            if (inventoryCheck != null) {
                inventoryChecker.setInventoryId(inventoryCheck.getId());
                inventoryChecker.setInAvailabelQuantity(inventoryCheck.getAvailableQuantity());
                inventoryChecker.setInWithholdingQuantity(inventoryCheck.getWithholdingQuantity());
            }
            if (warehouseInfo != null) {
                inventoryChecker.setWarehouseAreaId(warehouseInfo.getId());
                inventoryChecker.setWarehouseId(warehouseInfo.getWarehouseId());
            } else {
                inventoryChecker.setWarehouseAreaId("-1");
                inventoryChecker.setWarehouseId("-1");
            }
            if (goods.get(x.getGoodsCode()) != null) {
                inventoryChecker.setGoodsId(goods.get(x.getGoodsCode()).getScItemId());
            } else {
                inventoryChecker.setGoodsId("-1");
            }
            inventoryChecker.setExcelId("BIVC" + x.getExcelId());
            inventoryChecker.setCheckStatus(failStatus.getValue());
            inventoryChecker.setCheckMsg(failStatus.getLabel());
            inventoryChecker.setType(2);
            create(inventoryChecker);
        });
        InventoryCheckResult inventoryCheckResult = new InventoryCheckResult();
        return Result.success(inventoryCheckResult);
    }
}
